import { request } from 'ice';

export default {
  login: async (data) => {
    return await request({
      url: '/api/sys/login',
      method: 'POST',
      headers: {},
      data,
    });
  },
  captcha: async (params) => {
    const res = await request({
      url: '/api/captcha.jpg',
      method: 'GET',
      headers: { token: false },
      params,
      responseType: 'blob',
    });
    const blob = new Blob([res], { type: 'image/png' });
    const url = window.URL.createObjectURL(blob);
    return url;
  },
  getUsers: async (params) => {
    const reParams = { page: params.current, limit: params.pageSize, ...params };
    delete reParams.current;
    delete reParams.pageSize;

    return await request({
      url: '/api/sys/user/list',
      method: 'GET',
      params: reParams,
    });
  },
  getUser: async (userId) => {
    return await request({
      url: `/api/sys/user/info/${userId}`,
      method: 'GET',
    });
  },
  getCurrent: async () => {
    return await request({
      url: '/api/sys/user/info',
      method: 'GET',
    });
  },
  addUser: async (data) => {
    return await request({
      url: '/api/sys/user/save',
      method: 'POST',
      data,
    });
  },
  updateUser: async (data) => {
    return await request({
      url: '/api/sys/user/update',
      method: 'POST',
      data,
    });
  },
  delUsers: async (ids) => {
    return await request({
      url: '/api/sys/user/delete',
      method: 'POST',
      data: ids,
    });
  },
};
